<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>投诉表单页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <script src="../../res/layui/layui.js"></script>
    <script src="../../res/js/jquery.js"></script>
<!--    <script type="text/html" id="barDemo1">-->
<!--        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
<!--    </script>-->
    <script>
        layui.use(['form', 'layedit', 'laydate','jquery'], function(){
            var form = layui.form
                ,layer = layui.layer
                ,layedit = layui.layedit
                ,$ = layui.$
                ,laydate = layui.laydate;

            // $("#userName").val(getQueryString("userId"));
            // let typeId = getQueryString("orderId");
            $("#orderId").val(getQueryString("orderId"));
            //如果id有值
            // if (typeId){
            //     let url = "/NewsTypeServlet?action=showUpdate";
            //     let data = {typeId:typeId};
            //     $.post(url, data, function (resp) {
            //         if (resp.state==1){
            //             form.val('example', resp.data);
            //
            //             form.render();
            //         }
            //     },"json");
            // }

            // $("#userName").on("blur",function () {
            //     if (!$("#userId").val()){
            //         let url = "/javaweb/BookUserServlet?action=query&userName=";
            //         $.post(url, function (resp) {
            //
            //         },"json");
            //     }
            // });

            //日期
            laydate.render({
                elem: '#userBirthday'
            });
            laydate.render({
                elem: '#date1'
            });

            //创建一个编辑器
            var editIndex = layedit.build('LAY_demo_editor');

            //自定义验证规则
            form.verify({
                // title: function(value){
                //     if(value.length < 5){
                //         return '标题至少得5个字符啊';
                //     }
                // }
                pass: [
                    /^[\S]{6,12}$/
                    ,'密码必须6到12位，且不能出现空格'
                ]
                ,content: function(value){
                    layedit.sync(editIndex);
                }
            });
            //监听提交
            form.on('submit(tijiao)', function(data){
                // layer.alert(JSON.stringify(data.field), {
                //     title: '最终的提交信息'
                // })
                let url = "/logisticsAftermarket/addAftermarket";
                let data_ = data.field;

                $.post(url,data_,function (resp) {
                    // layer.msg(resp.msg);

                    if(resp.state==1){
                        //注意：parent 是 JS 自带的全局对象，可用于操作父页面
                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                        parent.layer.close(index);
                        //父页面刷新
                        // parent.table.reload('newsTypeListTable');

                        //父页面提示信息
                        parent.layer.msg(resp.msg);

                    }else{
                        layer.msg(resp.msg);
                    }
                },"json");
                return false;
            });
        });
        /**
         得到地址栏的参数
         */
        function getQueryString(name){
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if(r!=null)return  unescape(r[2]); return null;
        }
    </script>

</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>投诉</legend>
</fieldset>
<form class="layui-form" action="" lay-filter="example" id="myform">
    <input type="hidden" name="orderId" id="orderId">
    <input type="hidden" name="aftermarketState" id="aftermarketState" value="未处理">
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">投诉原因：</label>
        <div class="layui-input-block">
            <div style="width:750px">
                <textarea placeholder="" class="layui-textarea" name="aftermarketComment" id="aftermarketComment"></textarea>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" lay-submit="" lay-filter="tijiao">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</div>
</body>
</html>